package com.yulongtian.weekCompetition.month202212.week2;

import java.util.Arrays;
import java.util.HashMap;

/**
 * 可
 *
 * @author yulongTian
 * @create 2022-12-11 10:49
 */
public class Test12 {
    public static void main(String[] args) {
        int[] nums = {2, 3, 5, 6, 7};
        System.out.println(longestSquareStreak(nums));
    }

    public static int longestSquareStreak(int[] nums) {
        //元素值 是否被使用
        HashMap<Integer, Boolean> myMap = new HashMap<>();
        for (int num : nums) {
            myMap.put(num, false);
        }

        //排序
        Arrays.sort(nums);

        //结果  最长方波长度

        int res = 0;
        for (int num : nums) {
            int tempRes = 1;
            int temp = num;
            while (true) {
                temp *= temp;
                if (myMap.containsKey(temp)) {
                    if (!myMap.get(temp)) {
                        tempRes++;
                        myMap.put(temp, true);
                    } else {
                        if (tempRes != 1) {
                            res = Math.max(res, tempRes);
                        }
                        break;
                    }
                } else {
                    if (tempRes != 1) {
                        res = Math.max(res, tempRes);
                    }
                    break;
                }
            }
        }


        return res == 0 ? -1 : res;
    }
}
